/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on Jul 26, 2010, 1:47:06 PM
 */

package gui;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JSlider;

import parser.TabletConnector;

/**
 *
 * @author darek
 */
public class MainWindow extends javax.swing.JFrame {
    /**
	 * 
	 */
	private static final long serialVersionUID = -1273586386161621316L;
	private TabletConnector tc=null;

    /** Creates new form MainWindow */
    public MainWindow() {
        initComponents();
        CharacterWindow cw=new CharacterWindow();
        cw.setVisible(true);
        tc=new TabletConnector(panel, cw);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {

        panel = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator5 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        jSeparator6 = new javax.swing.JSeparator();
        line1 = new javax.swing.JLabel();
        line2 = new javax.swing.JLabel();
        line3 = new javax.swing.JLabel();
        line4 = new javax.swing.JLabel();
        line5 = new javax.swing.JLabel();
        jSeparator7 = new javax.swing.JSeparator();
        line6 = new javax.swing.JLabel();
        jSeparator8 = new javax.swing.JSeparator();
        line7 = new javax.swing.JLabel();
        jSeparator9 = new javax.swing.JSeparator();
        line8 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        factor = new javax.swing.JSlider();
        factorWindow = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(50, 50, 0, 0));
        setResizable(false);

        panel.setBackground(new java.awt.Color(255, 204, 51));

        jSeparator1.setForeground(new java.awt.Color(204, 102, 0));

        jSeparator3.setForeground(new java.awt.Color(204, 102, 0));

        jSeparator5.setForeground(new java.awt.Color(204, 102, 0));

        jSeparator4.setForeground(new java.awt.Color(204, 102, 0));

        jSeparator6.setForeground(new java.awt.Color(204, 102, 0));

        line1.setFont(new java.awt.Font("Tahoma", 0, 24));
        line1.setForeground(new java.awt.Color(204, 153, 0));
        line1.setText(" ");

        line2.setFont(new java.awt.Font("Tahoma", 0, 24));
        line2.setForeground(new java.awt.Color(204, 153, 0));
        line2.setText(" ");

        line3.setFont(new java.awt.Font("Tahoma", 0, 24));
        line3.setForeground(new java.awt.Color(204, 153, 0));
        line3.setText(" ");

        line4.setFont(new java.awt.Font("Tahoma", 0, 24));
        line4.setForeground(new java.awt.Color(204, 153, 0));
        line4.setText(" ");

        line5.setFont(new java.awt.Font("Tahoma", 0, 24));
        line5.setForeground(new java.awt.Color(204, 153, 0));
        line5.setText(" ");

        jSeparator7.setForeground(new java.awt.Color(204, 102, 0));

        line6.setFont(new java.awt.Font("Tahoma", 0, 24));
        line6.setForeground(new java.awt.Color(204, 153, 0));
        line6.setText(" ");

        jSeparator8.setForeground(new java.awt.Color(204, 102, 0));

        line7.setFont(new java.awt.Font("Tahoma", 0, 24));
        line7.setForeground(new java.awt.Color(204, 153, 0));
        line7.setText(" ");

        jSeparator9.setForeground(new java.awt.Color(204, 102, 0));

        line8.setFont(new java.awt.Font("Tahoma", 0, 24));
        line8.setForeground(new java.awt.Color(204, 153, 0));
        line8.setText(" ");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel1.setForeground(new java.awt.Color(102, 0, 0));
        jLabel1.setText("wspolczynnik odciecia:");

        factor.setBackground(new java.awt.Color(255, 204, 51));
        factor.setForeground(new java.awt.Color(102, 0, 0));
        factor.setValue(5);
        factor.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                factorStateChanged(evt);
            }
        });

        factorWindow.setBackground(new java.awt.Color(255, 204, 51));
        factorWindow.setFont(new java.awt.Font("Tahoma", 0, 14));
        factorWindow.setForeground(new java.awt.Color(102, 0, 0));
        factorWindow.setText("0.05");

        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addComponent(jSeparator6, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addComponent(jSeparator5, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addGroup(panelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(line1)
                        .addGap(18, 18, 18)
                        .addComponent(factorWindow, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addComponent(factor, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(line2)
                    .addComponent(line3)
                    .addComponent(line4)
                    .addComponent(line5)
                    .addComponent(jSeparator7, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addComponent(line6)
                    .addComponent(jSeparator8, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addComponent(line7)
                    .addComponent(jSeparator9, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addComponent(line8))
                .addContainerGap())
        );
        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayout.createSequentialGroup()
                .addContainerGap(44, Short.MAX_VALUE)
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(line1)
                    .addComponent(jLabel1)
                    .addComponent(factorWindow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(factor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(line2)
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(line3)
                .addGap(21, 21, 21)
                .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(line4)
                .addGap(21, 21, 21)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(line5)
                .addGap(21, 21, 21)
                .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(line6)
                .addGap(21, 21, 21)
                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(line7)
                .addGap(21, 21, 21)
                .addComponent(jSeparator8, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(line8)
                .addGap(21, 21, 21)
                .addComponent(jSeparator9, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jMenu1.setText("Menu");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setText("Wczytaj tekst...");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Nowa probka...");
        jMenuItem2.setEnabled(false);
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Wyczysc");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        System.out.println("openning new window...");
        JFileChooser jfc=new JFileChooser(new File("D:/HCR/quot"));
        jfc.showOpenDialog(panel);
        File f=jfc.getSelectedFile();
        if(f==null)return;
        System.out.println("file returned...");
        JLabel[] labelList={line1, line2, line3, line4, line5, line6, line7, line8};
        try {
            BufferedReader in=new BufferedReader(new FileReader(f));
            for(JLabel l: labelList){
                String line=in.readLine();
                if(line==null)return;
                l.setText(line);
                System.out.println(line);
                l.repaint();
                System.out.println("wczytywanie tekstu");
            }
        } catch (FileNotFoundException ex) {
            System.out.println("file not found exception");
        } catch (IOException ex){
            System.out.println("IOException");
        }
//        panel.repaint();
    }                                          

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
//        new NewPatternWindow(this).setVisible(true);
    }                                          

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        panel.repaint();
    }                                          

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
    }                                      

    private void factorStateChanged(javax.swing.event.ChangeEvent evt) {                                    
        JSlider js=(JSlider)evt.getSource();
        double result=js.getValue();
        factorWindow.setText(""+result/100.0);
        tc.setFactor(result/100.0);
    }                                   

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        new MainWindow().setVisible(true);
    }

    // Variables declaration - do not modify                     
    private javax.swing.JSlider factor;
    private javax.swing.JTextField factorWindow;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JSeparator jSeparator9;
    private javax.swing.JLabel line1;
    private javax.swing.JLabel line2;
    private javax.swing.JLabel line3;
    private javax.swing.JLabel line4;
    private javax.swing.JLabel line5;
    private javax.swing.JLabel line6;
    private javax.swing.JLabel line7;
    private javax.swing.JLabel line8;
    private javax.swing.JPanel panel;
    // End of variables declaration                   

}
